/*
 * Copyright 2014 Davy Maddelein.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.compomics.pepshell.view.dataloading;

import com.compomics.pepshell.model.protein.proteinimplementations.PepshellProtein;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author Davy Maddelein
 */
public class PreloadProteinFilterPanel extends javax.swing.JPanel {

    /**
     * Creates new form PreloadProteinFilterPanel
     */
    //probably replace the accession text area with a list with add and remove buttons
    public PreloadProteinFilterPanel() {
        initComponents();
    }

    public List<PepshellProtein> getProteinsToFilterWith() {
        List<PepshellProtein> filterList = new ArrayList<>();
        if (!accessionTextArea.getText().isEmpty()) {
            for (String accession : Arrays.asList(accessionTextArea.getText().split("\n"))) {
                filterList.add(new PepshellProtein(accession));
            }
        }
        return filterList;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        accessionScrollPane = new javax.swing.JScrollPane();
        accessionTextArea = new javax.swing.JTextArea();
        filterCheckbox = new javax.swing.JCheckBox();
        importSubsetButton = new javax.swing.JButton();
        saveSubsetButton = new javax.swing.JButton();

        accessionTextArea.setColumns(20);
        accessionTextArea.setRows(5);
        accessionTextArea.setText("list of accessions separated by enters");
        accessionScrollPane.setViewportView(accessionTextArea);

        filterCheckbox.setText("remove this subset instead");
        filterCheckbox.setOpaque(false);

        importSubsetButton.setText("import subset ...");

        saveSubsetButton.setText("save subset...");
        saveSubsetButton.setMaximumSize(new java.awt.Dimension(113, 23));
        saveSubsetButton.setMinimumSize(new java.awt.Dimension(113, 23));
        saveSubsetButton.setPreferredSize(new java.awt.Dimension(113, 23));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(accessionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(filterCheckbox)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(importSubsetButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(saveSubsetButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(176, 176, 176))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(filterCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(importSubsetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(saveSubsetButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(accessionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane accessionScrollPane;
    private javax.swing.JTextArea accessionTextArea;
    private javax.swing.JCheckBox filterCheckbox;
    private javax.swing.JButton importSubsetButton;
    private javax.swing.JButton saveSubsetButton;
    // End of variables declaration//GEN-END:variables
}
